package org.turistmontoro.ocio;

import org.turistmontoro.R;
import org.turistmontoro.adaptadores.FragmentAdapterOcioDetails;
import org.turistmontoro.genericDetails.DetailsActivity;
import org.turistmontoro.monumentos.BaseActivity;
import org.turistmontoro.utils.Utils;


import android.content.Intent;

import com.google.gson.Gson;
import com.viewpagerindicator.TitlePageIndicator;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;

public class ManejadorOcio extends ActionBarActivity {

	private FragmentAdapterOcioDetails mAdapter;

	private ViewPager mPager;
	private TitlePageIndicator mIndicator;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		this.setContentView(R.layout.view_pager);

		mAdapter = new FragmentAdapterOcioDetails(getSupportFragmentManager());

		mPager = (ViewPager) findViewById(R.id.pager);

		mPager.setAdapter(mAdapter);

		mIndicator = (TitlePageIndicator) findViewById(R.id.indicator);
		mIndicator.setViewPager(mPager);

		// Ponemos titulo al action bar
		ActionBar ab = getSupportActionBar();

		// //Ponemos titulo al action bar y mostramos el bton home
		ab.setDisplayHomeAsUpEnabled(true);
		ab.setIcon(R.drawable.ic_escudo_montoro);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		getMenuInflater().inflate(R.menu.main, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		super.onOptionsItemSelected(item);

		switch (item.getItemId()) {

		case R.id.infoTurist:

			Gson gson = new Gson();
			Intent i = new Intent(this, DetailsActivity.class);
			i.putExtra("detalle",
					gson.toJson(Utils.obtenerInfoOficinaTurismo()));
			startActivity(i);
			break;

		case android.R.id.home:
			Intent intent = new Intent(this, BaseActivity.class);
			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
			break;
		}
		return true;

	}
}
